home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / WWShaders / WWBloodShot.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  3.8 KB  |  105 lines

  1. /*
  2.  * WWBloodShot.sl : a bloodshot shader derived from Larry Gritz's eyeball shader
  3.  *
  4.  * DESCRIPTION:
  5.  *   Makes a plastic-like surface which looks like the white part of an eyeball. 
  6.  *   for use on a sphere.  The center of the pupil is at the "north pole",
  7.  *   i.e. where the t parameter is 1.  The colors of the pupil, iris, white
  8.  *   part (eyeball), and blood vessels can be set individually.  Fractal
  9.  *   functions are used for the veining and the iris mottling.
  10.  * 
  11.  * PARAMETERS:
  12.  *   Ka, Kd, Ks, roughness, specularcolor - work just like the plastic shader
  13.  *   eyeballcolor - color of the white part of the eyeball
  14.  *   bloodcolor - color of the blood vessels
  15.  *   bloodshot - controls how bloodshot the eye is (0=no blood, 1=very ugly)
  16.  *   veinfreq, veinlevel - control the formation of the blood vessels
  17.  *   index - set between 0 and 1, lets you use this shader to generate
  18.  *           non-identical eyeballs.
  19.  *
  20.  * AUTHOR: written by wave; hacked from Larry Gritz's eyeball shader
  21.  *
  22.  * HISTORY:
  23.  *      Nov 1991 - crude written of "eye" by lg for Herman's eyes for
  24.  *                 "Graphic Violence".  Original version hard coded in C.
  25.  *      Dec 1993 - "eye" modified by lg to clean up a bit.
  26.  *      10 Jan 1994 - recoded by lg in correct shading language.
  27.  *      28 Jun 94 (lg) - revamped to add veins and iris mottling, renamed
  28.  *                       "eyeball"
  29.  *       7 Jan 95 (wave) - changed name to LGEyeBall for namespace reasons...
  30.  *       8 Jan 95 (wave) - changed Ciris line to fix bug Larry figured out and changed defaults
  31.  *       15 Jan 95 (wave) - ripped out the iris and pupil stuff
  32.  *
  33.  * last modified  15 Jan 95 by Michael B. Johnson (wave)
  34.  */
  35.  
  36.  
  37.  
  38. surface
  39. WWBloodShot (float Ka = .75, Kd = 0.75, Ks = 0.4, roughness = 0.1;
  40.      color specularcolor = 1;
  41.      color eyeballcolor = color(1,1,1);
  42.      color bloodcolor = color(.8,.05,.05);
  43.      float bloodshot = 1.0;
  44.      float irissize = 0.12;
  45.      float veinfreq = 8, veinlevel = 4;
  46.      float index = 0;
  47.         )
  48. {
  49. #define snoise(P) (2*noise(P)-1)
  50. #define MINFILTERWIDTH 1.0e-7
  51.   color Ct;
  52.   point Nf;
  53.   point PP, PO;
  54.   float i, turb, newturb, freq, f2;
  55.   float displayed, newdisp;
  56.   color Cball, Ciris;
  57.   float irisstat, pupilstat;
  58.   float bloody, tt;
  59.   float ks, rough;
  60.   float twidth, cutoff;
  61.  
  62.   /* Calculate an appropriate filter width for antialiasing */
  63.   twidth = max (abs(Du(t)*du) + abs(Dv(t)*dv), MINFILTERWIDTH);
  64.   PO = transform ("object", P);
  65.  
  66.   /* Figure out where we are in the eyeball.  Use the following variables:
  67.    * irisstat: 0 inside the iris/white boundary, 1 outside
  68.    * pupilstat: 0 inside the pupil/iris boundary, 1 outside
  69.    * bloody: how potentially bloody it is (fade as we get away from iris)
  70.    */
  71.   tt = 1-t;
  72.   irisstat = 1;
  73.   pupilstat = 1;
  74.   bloody = bloodshot * (smoothstep (-irissize, 2.5*irissize, tt));
  75.  
  76.   /* If we're somewhere in the white part and it's potentially bloody,
  77.    * then calculate the veining pattern.  Otherwise, just use the color
  78.    * of the whites.  The veining pattern is essentially summed zero sets
  79.    * of turbulence functions.  Some stretching is done to get it to look
  80.    * just right.
  81.    */
  82.   if (irisstat * bloody > 0.001) 
  83.   {   turb = bloody;  freq = veinfreq;
  84.       displayed = 0;
  85.       for (i = 1;  (i <= veinlevel) && (turb > 0.1);  i += 1)
  86.       {      newturb = 1 - abs (snoise(PO*freq + point(0,0,20*freq)));
  87.       newdisp = pow (smoothstep (.85, 1, newturb), 10);
  88.       displayed += (1-displayed) * newdisp * smoothstep (.1, .85, turb * turb);
  89.       turb *= newturb;
  90.       freq *= 2;
  91.       }
  92.       Ct = mix (eyeballcolor, bloodcolor, smoothstep(0,.75,displayed));
  93.   }
  94.   else 
  95.   {  Ct = eyeballcolor;
  96.   }
  97.  
  98.   /* Now shade like plastic */
  99.   Oi = Os;
  100.   Nf = faceforward (normalize(N),I);
  101.   Ci = Os * ( Ct * (Ka*ambient() + Kd*diffuse(Nf)) +
  102.           specularcolor * Ks*specular(Nf,-normalize(I),roughness));
  103. }
  104.  
  105.